//
//  TalkfunIncrease.swift
//  test
//
//  Created by 莫瑞权 on 2021/12/3.
//

import UIKit
//增大点击区域
class TalkfunIncreaseButton: UIButton {

    @objc public var spacing: CGFloat = 0
    @objc public let layerBorderColorView = UIView()
    @objc public let colorView = UIView()
    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
        
        let biggerFrame =  self.bounds.insetBy(dx: -20, dy:  -20)

        return biggerFrame.contains(point)
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubview(self.layerBorderColorView)
        self.addSubview(self.colorView)
        self.colorView.isHidden = true
        self.colorView.backgroundColor = UIColor(red: 0.25, green: 0.59, blue: 0.92, alpha: 1)
        
        self.layerBorderColorView.isUserInteractionEnabled = false
        self.colorView.isUserInteractionEnabled = false
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
        if (self.spacing > 0 )
        {
            let imageViewW = 20.0
            self.imageView?.frame = CGRect(x: 0.0, y: 0.0, width:imageViewW , height: self.frame.height)
            
            self.titleLabel?.frame = CGRect(x: imageViewW + self.spacing, y: 0, width: self.frame.width - self.spacing - self.spacing, height: self.frame.size.height);
        }
        self.layerBorderColorView.frame = CGRect(x: -3, y: -2, width: self.frame.size.width + 6, height: self.frame.size.height + 4)
        
        
        self.colorView.frame = CGRect(x: -4, y: -4, width: 40, height: 40)
        
        //设置裁剪
        self.colorView.layer.masksToBounds = true

       // 圆角半径  能把一个下正文体,改成圆形
        self.colorView.layer.cornerRadius = 20;
    }
}
